package com.dhl.fin.api.controller;

import com.dhl.fin.api.common.controller.CommonController;
import com.dhl.fin.api.common.dto.ApiResponse;
import com.dhl.fin.api.common.dto.QueryDto;
import com.dhl.fin.api.common.util.ObjectUtil;
import com.dhl.fin.api.common.util.WebUtil;
import com.dhl.fin.api.domain.Family;
import com.dhl.fin.api.domain.FixDeposit;
import com.dhl.fin.api.service.FamilyService;
import com.dhl.fin.api.service.FixDepositService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author CuiJianbo
 * @since 2025/3/16
 */
@Transactional(rollbackFor = Exception.class)
@RestController
@RequestMapping("fixdeposit")
public class FixDepositController extends CommonController<FixDeposit> {

    @Autowired
    private FixDepositService fixDepositService;

    @Autowired
    private FamilyService familyService;

    @ResponseBody
    @GetMapping("child/deposit")
    public ApiResponse familyInfo(String unicode) throws Exception {

        Family family = familyService.get(QueryDto.builder()
                .available()
                .addWhere("wx_account_code='" + WebUtil.getLoginUser().getUuid() + "'")
                .build());

        if (ObjectUtil.isNull(family)) {
            return ApiResponse.error("请添加家庭成员");
        }

        List bankAccountList = fixDepositService.composeDataByChild(unicode);
        return ApiResponse.success(bankAccountList);

    }

    @ResponseBody
    @GetMapping("calculatePenalty")
    public ApiResponse calculatePenalty(Long fixDepositId, String unicode) throws Exception {
        Map result = fixDepositService.calculatePenalty(fixDepositId, unicode);
        return ApiResponse.success(result);
    }


}
